package pl.smath.expression.model.presentation;

import pl.smath.expression.model.Term;

public class IntervalTerm extends PresentationTerm {

	private IntervalClosureType closureType;
	private Term first;
	private Term second;
	
	public IntervalTerm(String closureTypeString, Term first, Term second) {
		super("");
		this.first = first;
		this.second = second;
		this.closureType = IntervalClosureType.fromString(closureTypeString);
	}
	
	public IntervalClosureType getClosureType() {
		return closureType;
	}

	public Term getFirst() {
		return first;
	}

	public void setFirst(Term first) {
		this.first = first;
	}

	public Term getSecond() {
		return second;
	}

	public void setSecond(Term second) {
		this.second = second;
	}

	/**
	 * Sprawdzenie czy 2 wartości bezwgledne wyrazenia sa sobie równowazne.
	 */
	public boolean isAbsTheSame(Term term){
		if (!(term instanceof IntervalTerm))
			return false;
		
		IntervalTerm it = (IntervalTerm)term;
		
		if (it.getClosureType() != getClosureType())
			return false;
		
		if (!it.getFirst().isAbsTheSame(getFirst())  ||  !it.getSecond().isAbsTheSame(getSecond()))
			return false;
		
		return true;
	}
	
	public String toString(){
		String output = first.toString() + "," + second.toString();
		
		if (closureType == IntervalClosureType.CLOSED  ||  closureType == IntervalClosureType.CLOSED_OPEN)
			output = "<" + output;
		else
			output = "(" + output;
		
		if (closureType == IntervalClosureType.CLOSED  ||  closureType == IntervalClosureType.OPEN_CLOSED)
			output = output + ">";
		else
			output = output + ")";
		
		return output;
	}
}
